#!/bin/bash

# Install script for CPU Scheduler GUI

echo "Installing CPU Scheduler GUI..."

# Check if running as root
if [ "$EUID" -ne 0 ]; then
    echo "Please run as root (use sudo)"
    exit 1
fi

# Build the project first
./build.sh

if [ $? -ne 0 ]; then
    echo "Build failed, cannot install"
    exit 1
fi

# Create installation directory
INSTALL_DIR="/opt/ohmylinux/cpu-scheduler-gui"
mkdir -p $INSTALL_DIR

# Copy executable
cp build/cpu-scheduler-gui $INSTALL_DIR/

# Create desktop entry
DESKTOP_ENTRY="[Desktop Entry]
Name=CPU调度优化工具
Comment=CPU调度优化图形界面
Exec=$INSTALL_DIR/cpu-scheduler-gui
Icon=application-x-executable
Terminal=false
Type=Application
Categories=System;
"

echo "$DESKTOP_ENTRY" > /usr/share/applications/cpu-scheduler-gui.desktop

# Make desktop entry executable
chmod +x /usr/share/applications/cpu-scheduler-gui.desktop

echo "Installation completed!"
echo "You can now run the application from the applications menu or by executing:"
echo "$INSTALL_DIR/cpu-scheduler-gui"